import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:test/test.dart';

main() {
  setUpAll(() {
    const MethodChannel('plugins.flutter.io/shared_preferences')
        .setMockMethodCallHandler((MethodCall methodCall) async {
      if (methodCall.method == 'getAll') {
        return <String, dynamic>{}; // set initial values here if desired
      }
      return null;
    });
  });
  group('SharedPreferences', () {
    test('get', () async {
      final prefs = await SharedPreferences.getInstance();
      int counter = prefs.getInt('counter') ?? 0;
      expect(counter, 0);
    });

    test('set', () async {
      final prefs = await SharedPreferences.getInstance();
      // set value
      prefs.setInt('counter', 1);

      // Try reading data from the counter key. If it does not exist, return 0.
      final counter = prefs.getInt('counter') ?? 0;
      expect(counter, 1);
    });

    test('remove', () async {
      final prefs = await SharedPreferences.getInstance();

      prefs.remove('counter');

      int counter = prefs.getInt('counter') ?? 0;
      expect(counter, 0);
    });
  });
}
